<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/21
 * Time: 20:38
 */

namespace Home\Model;


use Think\Model;

class UsergoodsModel  extends Model
{
   protected  $tableName='usergoods';
    //向用户购物信息表中插入数据
    public  function store($data){
//          dd($data);die;
        $data['logintime']=time();
        $data['buytime']=time();
        $data['uid']=$data[0];
        $data['gid']=$data[1];
        $uid=$data['uid'];
        $gid=$data['gid'];
        //判断该用户购物车中有没有支付的该商品商品中
        if(!M('usergoods')->where("uid=$uid")->where("gid=$gid")->find()){
            $this->add($data);
            return $this->where("uid=$uid")->where("gid=$gid")->setInc('count',1);
        }else{
            return $this->where("uid=$uid")->where("gid=$gid")->setInc('count',1);
        }
    }
    //向用户购物信息表中添加数据
    public function addcar($data){
//        dd($data);die;
        //判断该用户购物车中有没有支付的该商品商品中
        $uid=$data['uid'];
        $gid=$data['gid'];
        $pcid=$data['pcid'];
//        echo 3333;die;
        if(!M('usergoods')->where("uid=$uid AND gid=$gid AND pcid=$pcid AND gstatus=0")->find()){
             if(!isset($data['count'])){
               $data['count']=1;
             }
            return   $this->add($data);
//                $this->where("uid=$uid AND gid=$gid")->setInc('count',1);
        }else{
            if(!isset($data['count'])){
                return $this->where("uid=$uid AND gid=$gid")->setInc('count',1);
            }
            return $this->where("uid=$uid AND gid=$gid")->setInc('count',$data['count']);

        }
    }
}